package libra;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;

public class CoustomConverter implements Converter<String, List<DegradeRule>> {
	@Override
	public List<DegradeRule> convert(String source) {
		try {
			System.out.println("读取：" + source);
			ObjectMapper objectMapper = new ObjectMapper();
			// 忽略不存在的自定义字段
			objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
			JavaType javaType = objectMapper.getTypeFactory().constructParametricType(ArrayList.class, DegradeRule.class);
			List<DegradeRule> readValue = objectMapper.readValue(source, javaType);
			return readValue;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return List.of();
	}
}
